package testcase;

import java.io.*;

import junit.framework.TestCase;

import org.junit.*;

import ui.UI;

public class TestUI extends TestCase{

	private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
	private ByteArrayInputStream inContent;
	
	@Before
	public void setUp(){
		System.setOut(new PrintStream(outContent));
	}
	
	@After
	public void cleanUp() throws Exception{
		outContent.reset();
		System.setOut(null);
	}

	@Test
	public void testShowMessage(){
		UI.showMessage("testing");
		assertEquals("testing\n", outContent.toString());
	}
	
	@Test
	public void testGetFilePath(){
		inContent = new ByteArrayInputStream("filepath".getBytes());
		System.setIn(inContent);
		
		assertEquals(UI.getFilePath(), "filepath");
		assertEquals("Please enter the saved html\n", outContent.toString());
	}
	
	@Test
	public void testGetUniversity(){
		inContent = new ByteArrayInputStream("cityu".getBytes());
		System.setIn(inContent);
		
		assertEquals(UI.getUniversity(), "cityu");
		assertEquals("Please enter the university you are in (cityu, polyu, hku, bu, ou, cu)\n", outContent.toString());
	}
	
	@Test
	public void testShowSuccessMessage(){
		UI.showSuccessMessage();
		assertEquals("The file is created successfully\n", outContent.toString());
	}

	@Test
	public void testShowFailMessage(){
		UI.showFailMessage();
		assertEquals("The file creation fails\n", outContent.toString());
	}
	
	@Test
	public void testShowErrorMessage(){
		UI.showErrorMessage("testing");
		assertEquals("FATAL ERROR: testing\n", outContent.toString());
	}
}
